package persistent.impl;

import java.util.List;

import basic.HibBaseDAO;
import model.VClassCheckPersonNumber;
import model.VClassEPQCheckReportStatis;
import model.VClassMHTCheckReportStatis;
import model.VGradeCheckPersonNumber;
import model.VGradeEPQCheckReportStatis;
import model.VGradeMHTCheckReportStatis;
import model.VSchoolCheckPersonNumber;
import model.VSchoolEPQCheckReportStatis;
import model.VSchoolMHTCheckReportStatis;
import persistent.dao.ICheckStatisDAO;

public class CheckStatisDAOImpl implements ICheckStatisDAO {

	HibBaseDAO dao = new HibBaseDAO();
	@Override
	public List<VClassMHTCheckReportStatis> getVClassMHTCheckReportStatisByClassId(
			String classid,String checktime) {
		String hql = "from VClassMHTCheckReportStatis where classId = ? and checktime = ? order by itemname";
		Object para[] = {classid,checktime};
		return dao.select(hql, para);
	}
	@Override
	public VClassCheckPersonNumber getClassCheckPersonNumberByCondition(
			int checktypeid, String classid,String checktime) {
		String hql = "from VClassCheckPersonNumber where checktypeid = ? "
				+ "and classID = ? and checktime = ?";
		Object para[] = {checktypeid,classid,checktime};
		List list =  dao.select(hql, para);
		if(list!=null && list.size()>0){
			return (VClassCheckPersonNumber)list.get(0);
		}else{
			return null;
		}
	}
	@Override
	public List<VClassMHTCheckReportStatis> getVClassMHTCheckReportStatisByCondition(
			String whereCondition) {
		String hql = "from VClassMHTCheckReportStatis " + whereCondition;
		return dao.select(hql);
	}
	@Override
	public List<VClassEPQCheckReportStatis> getVClassEPQCheckReportStatisByClassId(
			String classid, String checktime) {
			String hql = "from VClassEPQCheckReportStatis where classId = ? and checktime = ? order by itemname";
			Object para[] = {classid,checktime};
			return dao.select(hql, para);
	}
	@Override
	public List<VClassEPQCheckReportStatis> getVClassEPQCheckReportStatisByCondition(
			String whereCondition) {
		String hql = "from VClassEPQCheckReportStatis " + whereCondition;
		return dao.select(hql);
	}
	
	@Override
	public int getStatusNumberByEPQItemName(String itemname,String classID,String checktime) {
		String hql = "from VClassEPQCheckReportStatis where itemname = ? and"
				+ " classid = ? and checktime = ?" ;
		Object para[] = {itemname,classID,checktime};
		List list =  dao.select(hql,para);
		return list.size();
	}
	@Override
	public int getStatusNumberByMHTItemName(String itemname,String classID,String checktime) {
		String hql = "from VClassMHTCheckReportStatis where itemname = ? and"
				+ " classid = ? and checktime = ?" ;
		Object para[] = {itemname,classID,checktime};
		List list =  dao.select(hql,para);
		return list.size();
	}
	
	//TODO TODO 2018-11-09 14:34 基于年级
	@Override
	public List<VGradeMHTCheckReportStatis> getVGradeMHTCheckReportStatisByGradeName(
			String gradeName, String checktime) {
		String hql = "from VGradeMHTCheckReportStatis where gradename = ? and checktime = ? order by itemname";
		Object para[] = {gradeName,checktime};
		return dao.select(hql, para);
	}
	
	@Override
	public VGradeCheckPersonNumber getGradeCheckPersonNumberByCondition(
			int checktypeid, String gradeName, String checktime) {
		String hql = "from VGradeCheckPersonNumber where checktypeid = ? "
				+ "and gradename = ? and checktime = ?";
		Object para[] = {checktypeid, gradeName, checktime};
		List list =  dao.select(hql, para);
		if(list!=null && list.size()>0){
			return (VGradeCheckPersonNumber)list.get(0);
		}else{
			return null;
		}
	}
	
	@Override
	public List<VGradeMHTCheckReportStatis> getVGradeMHTCheckReportStatisByCondition(
			String whereCondition) {
		String hql = "from VGradeMHTCheckReportStatis " + whereCondition;
		return dao.select(hql);
	}
	
	@Override
	public List<VGradeEPQCheckReportStatis> getVGradeEPQCheckReportStatisByGradeName(
			String gradeName, String checktime) {
		String hql = "from VGradeEPQCheckReportStatis where gradename = ? and checktime = ? order by itemname";
		Object para[] = {gradeName, checktime};
		return dao.select(hql, para);
	}
	
	@Override
	public List<VGradeEPQCheckReportStatis> getVGradeEPQCheckReportStatisByCondition(
			String whereCondition) {
		String hql = "from VGradeEPQCheckReportStatis " + whereCondition;
		return dao.select(hql);
	}
	
	@Override
	public int getStatusNumberByEPQItemNameByGrade(String itemname, String gradeName,
			String checktime) {
		String hql = "from VGradeEPQCheckReportStatis where itemname = ? and"
				+ " gradename = ? and checktime = ?" ;
		Object para[] = {itemname, gradeName, checktime};
		List list =  dao.select(hql, para);
		return list.size();
	}
	
	@Override
	public int getStatusNumberByMHTItemNameByGrade(String itemname, String gradeName,
			String checktime) {
		String hql = "from VGradeMHTCheckReportStatis where itemname = ? and"
				+ " gradename = ? and checktime = ?" ;
		Object para[] = {itemname, gradeName, checktime};
		List list =  dao.select(hql,para);
		return list.size();
	}
	
	//TODO TODO 2018-11-09 16:00 基于学校
	
	@Override
	public List<VSchoolMHTCheckReportStatis> getVSchoolMHTCheckReportStatisByGradeName(
			String schoolid, String checktime) {
		String hql = "from VSchoolMHTCheckReportStatis where schoolid = ? and checktime = ? order by itemname";
		Object para[] = {schoolid, checktime};
		return dao.select(hql, para);
	}
	
	@Override
	public VSchoolCheckPersonNumber getSchoolCheckPersonNumberByCondition(
			int checktypeid, String schoolid, String checktime) {
		String hql = "from VSchoolCheckPersonNumber where checktypeid = ? "
				+ "and schoolid = ? and checktime = ?";
		Object para[] = {checktypeid, schoolid, checktime};
		List list =  dao.select(hql, para);
		if(list!=null && list.size()>0){
			return (VSchoolCheckPersonNumber)list.get(0);
		}else{
			return null;
		}
	}
	
	@Override
	public List<VSchoolMHTCheckReportStatis> getVSchoolMHTCheckReportStatisByCondition(
			String whereCondition) {
		String hql = "from VSchoolMHTCheckReportStatis " + whereCondition;
		return dao.select(hql);
	}
	
	@Override
	public List<VSchoolEPQCheckReportStatis> getVSchoolEPQCheckReportStatisByGradeName(
			String schoolid, String checktime) {
		String hql = "from VSchoolEPQCheckReportStatis where schoolid = ? and checktime = ? order by itemname";
		Object para[] = {schoolid, checktime};
		return dao.select(hql, para);
	}
	
	@Override
	public List<VSchoolEPQCheckReportStatis> getVSchoolEPQCheckReportStatisByCondition(
			String whereCondition) {
		String hql = "from VSchoolEPQCheckReportStatis " + whereCondition;
		return dao.select(hql);
	}
	
	@Override
	public int getStatusNumberByEPQItemNameBySchool(String itemname,
			String schoolid, String checktime) {
		String hql = "from VSchoolEPQCheckReportStatis where itemname = ? and"
				+ " schoolid = ? and checktime = ?" ;
		Object para[] = {itemname, schoolid, checktime};
		List list =  dao.select(hql, para);
		return list.size();
	}
	
	@Override
	public int getStatusNumberByMHTItemNameBySchool(String itemname,
			String schoolid, String checktime) {
		String hql = "from VSchoolMHTCheckReportStatis where itemname = ? and"
				+ " schoolid = ? and checktime = ?" ;
		Object para[] = {itemname, schoolid, checktime};
		List list =  dao.select(hql,para);
		return list.size();
	}

	public static void main(String[] args){
		CheckStatisDAOImpl dao = new CheckStatisDAOImpl();
		//System.out.println(dao.getStatusNumberByEPQItemName("外倾性（E）", 53, "2018-5-2"));
	}
}
